package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.FeeKey;
import com.atguigu.lease.model.entity.FeeValue;
import com.atguigu.lease.web.admin.service.FeeKeyService;
import com.atguigu.lease.web.admin.service.FeeValueService;
import com.atguigu.lease.web.admin.vo.fee.FeeKeyVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.w3c.dom.stylesheets.LinkStyle;

import java.util.List;

/**
 * Created by 小可乐$ on 2024/8/12$ 22:09$
 * description: 房间杂费管理
 */
@Tag(name = "杂费管理")
@RestController
@RequestMapping("/admin/fee")
public class FeeController {
    @Autowired
    private FeeKeyService feeKeyService;

    @Autowired
    private FeeValueService feeValueService;
    /**
     * 保存或者更新杂费值
     */
    @PostMapping("value/saveOrUpdate")
    @Operation(summary = "保存或者更新杂费值")
    public Result saveOrUpdateValue(
            @RequestBody FeeValue feeValue){
        feeValueService.saveOrUpdate(feeValue);
        return Result.ok();
    }
    /**
     *保存或更新杂费名称
     * */
    @PostMapping("key/saveOrUpdate")
    @Operation(summary = "保存或更新杂费名称")
    public Result saveOrUpdateKey(
            @RequestBody FeeKey feeKey){
        feeKeyService.saveOrUpdate(feeKey);
        return Result.ok();
    }

    /**
     * 查询全部杂费名称和杂费值列表
     * */
    @GetMapping("list")
    @Operation(summary = "查询全部杂费名称和杂费值列表")
    public Result<List<FeeKeyVo>> keyVoResult(){
         List<FeeKeyVo> list = feeKeyService.keyVoResult();
         return Result.ok(list);
    }

    /**
     * 根据id删除杂费值
     * */
    @DeleteMapping("/value/deleteById")
    @Operation(summary = "根据id删除杂费值")
    public Result deleteByIdValue(
            @RequestParam Long id){
        feeValueService.removeById(id);
        return Result.ok();
    }
    /**
     * 根据id删除杂费名
     * */
    @DeleteMapping("/key/deleteById")
    @Operation(summary = "根据id删除杂费名")
    public Result deleteByIdKey(
            @RequestParam Long id){
        feeKeyService.removeById(id);
        return Result.ok();
    }
}
